# Maintainer: Adam Jensen <acjensen@gmail.com>
pkgname=avida
pkgver=0_git20190813
_sha=ca1f311bc1bcaf021390c63bce6aa9455bbd44cc
_apto_sha=9184c91a3a82297c420540baaf355aac80213a29
pkgrel=1
pkgdesc="A scientific software platform for conducting and analyzing experiments with self-replicating and evolving computer programs"
url="https://avida.devosoft.org/"
arch="x86 x86_64" # build currently fails on non-intel arches
license="GPL-3.0-only"
makedepends="cmake linux-headers samurai"
source="$pkgname-$pkgver.tar.gz::https://github.com/devosoft/avida/archive/$_sha.tar.gz
	apto.tar.gz::https://github.com/dmbryson/apto/archive/$_apto_sha.tar.gz
	10-remove-forced-tcmalloc.patch
	musl123.patch
	"
builddir="$srcdir/avida-$_sha"

prepare() {
	rm -rf "$builddir"/libs/apto && mv "$srcdir"/apto-$_apto_sha "$builddir"/libs/apto

	default_prepare
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX:PATH=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DAVD_UNIT_TESTS:BOOL=ON \
		-DAVD_ENABLE_TCMALLOC:BOOL=OFF \
		-DHAVE_FUSED_MADD:BOOL=OFF \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS -Wno-expansion-to-defined"
	cmake --build build
}

check() {
	build/bin/unit-tests
}

package() {
	install -Dm755 build/bin/avida "$pkgdir"/usr/bin/avida
	mkdir -p "$pkgdir"/usr/share/avida
	cp -R avida-core/support/* "$pkgdir"/usr/share/avida
}

sha512sums="
09332469e4aab96c0775f3d8e5a8e9c2544468bd6b461e5a30edac2d6fb0049fbb4db4860e54d94a2f010830a593377bc5345404ca6d78acba1e968a352f889d  avida-0_git20190813.tar.gz
e0f8aab74198f07e2edbd0d5083792eaab91a96c4065e1bba6295bb4d6a784665744d812ce1e40393a1da015a9048cbc6c15229dd20da2de9f32692b0d870cfb  apto.tar.gz
be92b7f3015cccaa64f2065bb552237176b044cbc16fa6dcef368b02aa53c9c3fdcfbb608b4fea2d6d720fe2a01f3362da87bf427fcb95942486c06fddba2892  10-remove-forced-tcmalloc.patch
c1ef9b2176eba944fdb546fea64119a9515dfd8b3ab904eb7d7b621ac1d0734f7b20cd198df40356fa38280e21dfb126fb5601ca580a656c925f98338bb358cc  musl123.patch
"
